package com.xxq.semester.service.impl.exam;

import com.xxq.semester.entity.exam.ExamQuestions;
import com.xxq.semester.entity.question.Questions;
import com.xxq.semester.mapper.ExamQuestionsMapper;
import com.xxq.semester.service.exam.IExamQuestionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author saki
 * @since 2025-07-13
 */
@Service
public class ExamQuestionsServiceImpl extends ServiceImpl<ExamQuestionsMapper, ExamQuestions> implements IExamQuestionsService {

    @Override
    public List<ExamQuestions> listAll() {
        return this.list();
    }

    @Override
    public void saveSelectedQuestions(Long examId, List<Long> questionIds) {
        if (examId == null || questionIds == null || questionIds.isEmpty()) return;
        List<ExamQuestions> list = questionIds.stream()
            .map(qid -> {
                ExamQuestions eq = new ExamQuestions();
                eq.setExamId(examId.intValue());
                eq.setQuestionId(qid.intValue());
                return eq;
            })
            .toList();
        this.saveBatch(list);
    }
}
